package itsm.isperp.framework.utils;

import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2014-2-28
 * @since 1.0
 * 
 */
public final class ServerUtils {

	private static final String hexByte(byte b) {
		String s = "000000" + Integer.toHexString(b);
		return s.substring(s.length() - 2);
	}

	public static final String getMac() throws SocketException {
		Enumeration<NetworkInterface> el;
		String mac_s = "";
		el = NetworkInterface.getNetworkInterfaces();
		while (el.hasMoreElements()) {
			byte[] mac = el.nextElement().getHardwareAddress();
			if (mac == null)
				continue;
			if (mac != null && mac.length >= 6) {
				mac_s = hexByte(mac[0]) + "-" + hexByte(mac[1]) + "-"
						+ hexByte(mac[2]) + "-" + hexByte(mac[3]) + "-"
						+ hexByte(mac[4]) + "-" + hexByte(mac[5]);
				break;
			}
		}
		return mac_s.toUpperCase();

	}
}
